package org.sixtynine.stock.service.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.sixtynine.stock.dto.GridPramDTO;
import org.sixtynine.stock.dto.Page;
import org.sixtynine.stock.entity.BaseEntity;
import org.sixtynine.stock.entity.Company;
import org.sixtynine.stock.entity.DailyShareData;
import org.sixtynine.stock.entity.User;
import org.sixtynine.stock.service.CompanyService;
import org.sixtynine.stock.service.DailyShareDataService;
import org.sixtynine.stock.service.GenericService;
import org.sixtynine.stock.service.StockPersistentService;
import org.sixtynine.stock.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * main interface for persistent layer operations
 * 
 * @author Thilanka
 * 
 */
@Service
public class StockPersistentServiceImpl implements StockPersistentService {

	@Autowired
	private GenericService genericService;

	@Autowired
	private DailyShareDataService dailyShareDataService;

	@Autowired
	private UserService userService;

	@Autowired
	private CompanyService companyService;

	@Override
	public void saveOrUpdate(BaseEntity entity) {
		genericService.saveOrUpdate(entity);
	}

	@Override
	public void delete(BaseEntity entity) {
		genericService.delete(entity);
	}

	@Override
	public BaseEntity findById(int id, Class<? extends BaseEntity> clazz) {
		return genericService.findById(id, clazz);
	}

	@Override
	public List<BaseEntity> findByCriteria(Criterion criterion,
			Class<? extends BaseEntity> clazz) {
		return genericService.findByCriteria(criterion, clazz);
	}

	@Override
	public List<BaseEntity> findAll(Class<? extends BaseEntity> clazz) {
		return genericService.findAll(clazz);
	}

	@Override
	public List<DailyShareData> searchDailyShareData(int companyId,
			Date fromDate, Date toDate, String orderBy, String orderByName) {
		return dailyShareDataService.searchDailyShareData(companyId, fromDate,
				toDate, orderBy, orderByName);
	}

	@Override
	public List<BaseEntity> findLatestRecords(int numResuts, Class clazz,
			String orderBy, Criterion... criterion) {
		return genericService.findLatestRecords(numResuts, clazz, orderBy,
				criterion);
	}

	@Override
	public User findUserByUserName(String userName) {
		return userService.findUserByUserName(userName);
	}

	@Override
	public Page<DailyShareData> searchDailyShareData(int companyId,
			Date fromDate, Date toDate, String orderBy, String orderByName,
			GridPramDTO gridPramDTO) {
		return dailyShareDataService.searchDailyShareData(companyId, fromDate,
				toDate, orderBy, orderByName, gridPramDTO);
	}

	@Override
	public List<Company> searchCompany(int sectorId) {
		return companyService.searchCompany(sectorId);
	}

	@Override
	public boolean isEmailExist(String email) {
		return userService.isEmailExist(email);
	}

}
